package com.example.picturestorage.service;

import com.example.picturestorage.bean.Book;
import com.example.picturestorage.mapper.BookMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE, proxyMode = ScopedProxyMode.TARGET_CLASS)
public class BookServiceImpl implements BookService{

    @Autowired
    private BookMapper bookMapper;

    @Override
    public PageInfo<Book> findBookFenYe(int page, int pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Book> allBook = bookMapper.findAllBook();
        return new PageInfo<>(allBook);
    }

    @Override
    public List<Book> findAllBook() {
        return bookMapper.findAllBook();
    }

    @Override
    public int addBook(Book book) {
        return bookMapper.addBook(book);
    }

    @Override
    public void deleteAllBook() {
        bookMapper.deleteAllBook();
    }

    @Override
    public Book findBookById(Book book) {
        return bookMapper.findBookById(book);
    }

    @Override
    public void deleteBookById(Integer id) {
        bookMapper.deleteBookById(id);
    }

    @Override
    public void deleteBookOverId(Integer id) {
        bookMapper.deleteBookOverId(id);
    }

    @Override
    public Book findBookWithPublisherByBookId(Integer bookId) {
        return bookMapper.findBookWithPublisherByBookId(bookId);
    }
}
